package com.woniuxy.article.mapper;/**
 * @Description：
 * @Author：曹杰克
 * @CreateTime：2022/10/19 19:47
 */

import com.hc.entity.Paper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 *@Description：文章mapper
 *@CreateTime：2022/10/19 19:47
 *@Author：曹杰克
 */
@Mapper
public interface PaperMapper {

    /**
     * 用于查询指定用户的所有文章信息
     * 文章对应的分区
     * 评论
     * 点赞数、踩的数量
     * 作者的id
     * @param userId
     * @return
     */
    @Select("select * from hc_paper where user_id =#{userId}")
    @Results( {
            @Result(column = "user_id",property = "user.id",one = @One(select = "com.woniuxy.mapper.AreaMapper.getById")),
            @Result(column = "area_id",property = "area",one = @One(select = "com.woniuxy.mapper.AreaMapper.getById")),
            @Result(column = "id",property = "likenum",one = @One(select = "com.woniuxy.mapper.AgreeMapper.getAgreeNumByPaperId")),
            @Result(column = "id",property = "unlikenum",one = @One(select = "com.woniuxy.mapper.AgreeMapper.getDisAgreeNumByPaperId")),
            @Result(column = "id",property = "comments",many = @Many(select = "com.woniuxy.mapper.CommentMapper.getByPaperId"))

    })
    List<Paper> selectAllByUserId(int userId);

    /**
     * 根据文章id获取文章的所有信息
     * @param id
     * @return
     */
    @Select("select * from hc_paper where id =#{id}")
    @Results( {
            @Result(column = "user_id",property = "user.id",one = @One(select = "com.woniuxy.mapper.AreaMapper.getById")),
            @Result(column = "area_id",property = "area",one = @One(select = "com.woniuxy.mapper.AreaMapper.getById")),
            @Result(column = "id",property = "likenum",one = @One(select = "com.woniuxy.mapper.AgreeMapper.getAgreeNumByPaperId")),
            @Result(column = "id",property = "unlikenum",one = @One(select = "com.woniuxy.mapper.AgreeMapper.getDisAgreeNumByPaperId")),
            @Result(column = "id",property = "comments",many = @Many(select = "com.woniuxy.mapper.CommentMapper.getByPaperId"))
    })
    Paper selectByPaperId(int id);




}
